{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e6dc44c1",
   "metadata": {},
   "source": [
    "\n",
    "* 2022-11-12/week11\n",
    "*课程：python\n",
    "*记录人：梁米"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9394be85",
   "metadata": {},
   "source": [
    " # 本周内容：   \n",
    " 1.元组   \n",
    " 2.集合    \n",
    " 3.字典    \n",
    "  ## 1.元组（tuple）：\n",
    "      1.元组的基本概念和基本形态   \n",
    "      \n",
    "      2.元组的方法\n",
    "      \n",
    "      "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b6539d97",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1800001, 1800002, 1800003) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "user_info = 1800001,1800002,1800003\n",
    "print(user_info,type(user_info))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "faac7293",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1800001, 1800002, 1800003] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "user_info_list = [1800001,1800002,1800003]\n",
    "print(user_info_list,type(user_info_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a2b2579b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1800001\n",
      "(1800001, 1800002)\n"
     ]
    }
   ],
   "source": [
    "#取值\n",
    "print(user_info[0])\n",
    "#切片\n",
    "print(user_info[:2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e415d605",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "2a9f58bd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=11, tm_mday=2, tm_hour=19, tm_min=11, tm_sec=56, tm_wday=2, tm_yday=306, tm_isdst=0)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "13f15fea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on struct_time object:\n",
      "\n",
      "class struct_time(builtins.tuple)\n",
      " |  struct_time(iterable=(), /)\n",
      " |  \n",
      " |  The time value as returned by gmtime(), localtime(), and strptime(), and\n",
      " |  accepted by asctime(), mktime() and strftime().  May be considered as a\n",
      " |  sequence of 9 integers.\n",
      " |  \n",
      " |  Note that several fields' values are not the same as those defined by\n",
      " |  the C language standard for struct tm.  For example, the value of the\n",
      " |  field tm_year is the actual year, not year - 1900.  See individual\n",
      " |  fields' descriptions for details.\n",
      " |  \n",
      " |  Method resolution order:\n",
      " |      struct_time\n",
      " |      builtins.tuple\n",
      " |      builtins.object\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __reduce__(...)\n",
      " |      Helper for pickle.\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data descriptors defined here:\n",
      " |  \n",
      " |  tm_gmtoff\n",
      " |      offset from UTC in seconds\n",
      " |  \n",
      " |  tm_hour\n",
      " |      hours, range [0, 23]\n",
      " |  \n",
      " |  tm_isdst\n",
      " |      1 if summer time is in effect, 0 if not, and -1 if unknown\n",
      " |  \n",
      " |  tm_mday\n",
      " |      day of month, range [1, 31]\n",
      " |  \n",
      " |  tm_min\n",
      " |      minutes, range [0, 59]\n",
      " |  \n",
      " |  tm_mon\n",
      " |      month of year, range [1, 12]\n",
      " |  \n",
      " |  tm_sec\n",
      " |      seconds, range [0, 61])\n",
      " |  \n",
      " |  tm_wday\n",
      " |      day of week, range [0, 6], Monday is 0\n",
      " |  \n",
      " |  tm_yday\n",
      " |      day of year, range [1, 366]\n",
      " |  \n",
      " |  tm_year\n",
      " |      year, for example, 1993\n",
      " |  \n",
      " |  tm_zone\n",
      " |      abbreviation of timezone name\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data and other attributes defined here:\n",
      " |  \n",
      " |  n_fields = 11\n",
      " |  \n",
      " |  n_sequence_fields = 9\n",
      " |  \n",
      " |  n_unnamed_fields = 0\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Methods inherited from builtins.tuple:\n",
      " |  \n",
      " |  __add__(self, value, /)\n",
      " |      Return self+value.\n",
      " |  \n",
      " |  __contains__(self, key, /)\n",
      " |      Return key in self.\n",
      " |  \n",
      " |  __eq__(self, value, /)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __ge__(self, value, /)\n",
      " |      Return self>=value.\n",
      " |  \n",
      " |  __getattribute__(self, name, /)\n",
      " |      Return getattr(self, name).\n",
      " |  \n",
      " |  __getitem__(self, key, /)\n",
      " |      Return self[key].\n",
      " |  \n",
      " |  __getnewargs__(self, /)\n",
      " |  \n",
      " |  __gt__(self, value, /)\n",
      " |      Return self>value.\n",
      " |  \n",
      " |  __hash__(self, /)\n",
      " |      Return hash(self).\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __le__(self, value, /)\n",
      " |      Return self<=value.\n",
      " |  \n",
      " |  __len__(self, /)\n",
      " |      Return len(self).\n",
      " |  \n",
      " |  __lt__(self, value, /)\n",
      " |      Return self<value.\n",
      " |  \n",
      " |  __mul__(self, value, /)\n",
      " |      Return self*value.\n",
      " |  \n",
      " |  __ne__(self, value, /)\n",
      " |      Return self!=value.\n",
      " |  \n",
      " |  __rmul__(self, value, /)\n",
      " |      Return value*self.\n",
      " |  \n",
      " |  count(self, value, /)\n",
      " |      Return number of occurrences of value.\n",
      " |  \n",
      " |  index(self, value, start=0, stop=9223372036854775807, /)\n",
      " |      Return first index of value.\n",
      " |      \n",
      " |      Raises ValueError if the value is not present.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Class methods inherited from builtins.tuple:\n",
      " |  \n",
      " |  __class_getitem__(...) from builtins.type\n",
      " |      See PEP 585\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(time.localtime())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3f35c885",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1667387663.5010471"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.time() # 时间戳，可以记录互联网当中所有数据信息产生、销毁、创建等一系列行为"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "404f8a1f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_info.count(1800001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "462a8253",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_info.index(1800001)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "49b963e8",
   "metadata": {},
   "source": [
    " ## 2.集合：\n",
    " > 1.集合的概念和性质\n",
    " >> A.集合的唯一性    \n",
    " >> B.集合的无序性     \n",
    " \n",
    " > 2.集合的方法\n",
    " >> A.交集： 逻辑运算符：    setA & setB , setA.intersection(B) = 》应用：推荐系统  \n",
    " >> B.并集： 逻辑运算符：    setA | setB ,setA.union(B) = 》应用：快速统计两个集合元素的个数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "e7231344",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'banana', 'pear', 'apple', 'orange'} <class 'set'>\n"
     ]
    }
   ],
   "source": [
    "basket = {'apple','orange','apple','pear','orange','banana'}\n",
    "print(basket,type(basket))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "2ecc6aa6",
   "metadata": {},
   "outputs": [],
   "source": [
    "舞蹈社_user_id = {1800002,1800003,1800111,1800122}\n",
    "合唱团_user_id = {1800003,1800009,1800007,1800111,1801111}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "6a22f9be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800003, 1800111}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id & 合唱团_user_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "ecb32666",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800003, 1800111}"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id.intersection(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "b8cfb5f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社_user_id) + len(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "0df049b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社_user_id | 合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "3f32fd92",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800002, 1800003, 1800007, 1800009, 1800111, 1800122, 1801111}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id.union(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "a95d85fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考：如果是列表的话，想要找出重复的项？集合的价值\n",
    "舞蹈社_user_id_list = [1800002,1800003,1800111,1800122]\n",
    "合唱团_user_id_list = [1800003,1800009,1800007,1800111,1801111]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fed2b8f7",
   "metadata": {},
   "source": [
    " ## 3.字典（dict）： \n",
    " \n",
    " >1. 字典的概念和性质 \n",
    " >>A.性质       \n",
    " >>>a.无序性      \n",
    " >>>b.key是唯一的(没有重复）      \n",
    " >>>c.key是不可变的   \n",
    " \n",
    " >2. 字典的创建    \n",
    " >>a.按照字典的形态创建字典  \n",
    " ‘’‘\n",
    " 网新一班 = {\n",
    "    1800001：\"李华\",\n",
    "    1800002：\"小明\",\n",
    "    1800003：\"Jack\",\n",
    "    1800004：\"Marry\"\n",
    "}     \n",
    ">>b.使用dict（）方法创建字典     \n",
    "网新二班 = dict（\n",
    "   stu19000\n",
    " \n",
    " >3. 字典的方法 \n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "d2563381",
   "metadata": {},
   "outputs": [],
   "source": [
    "wechat = {\n",
    "    \"fgyqeu7489fhdjk\":[\"Zhichao\",\"冰岛\",\"朋友圈\",\"男\",\"159\",\"置顶聊天\",\"会话\"],\n",
    "    \"bfdjiwg84239fgd\":[\"Jack\",\"香港\"]\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "1133c5d8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Zhichao', '冰岛', '朋友圈', '男', '159', '置顶聊天', '会话']"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wechat[\"fgyqeu7489fhdjk\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "b5ac299f",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新1班 = {\n",
    "    1800001:\"李华\",\n",
    "    1800002:\"小明\",\n",
    "    1800003:\"Jack\",\n",
    "    1800004:\"Marry\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "75832651",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1800001: '李华', 1800002: '小明', 1800003: 'Jack', 1800004: 'Marry'} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "print(网新1班,type(网新1班))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "cd98a88e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'小明'"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网新1班[1800002]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "75358259",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新2班 = dict(\n",
    "    stu190001=\"小红\",\n",
    "    stu190002=\"小莉\",\n",
    "    stu190003=\"小张\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "64b2ca53",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu190001': '小红', 'stu190002': '小莉', 'stu190003': '小张'}"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网新2班"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "26426790",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'小莉'"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网新2班[\"stu190002\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "395097e9",
   "metadata": {},
   "source": [
    " # 课后：请大家预习字典的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "07bb85c9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
